package com.tianma315.wx.service.impl;


import com.tianma315.core.sys.dao.RoleDao;
import com.tianma315.core.sys.dao.UserDao;
import com.tianma315.core.sys.domain.UserDO;

import com.tianma315.wx.service.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


import java.util.List;


//                   _ooOoo_
//                  o8888888o
//                  88" . "88
//                  (| -_- |)
//                  O\  =  /O
//               ____/`---'\____
//             .'  \\|     |//  `.
//            /  \\|||  :  |||//  \
//           /  _||||| -:- |||||-  \
//           |   | \\\  -  /// |   |
//           | \_|  ''\---/''  |   |
//           \  .-\__  `-`  ___/-. /
//         ___`. .'  /--.--\  `. . __
//      ."" '<  `.___\_<|>_/___.'  >'"".
//     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//     \  \ `-.   \_ __\ /__ _/   .-` /  /
//======`-.____`-.___\_____/___.-`____.-'======
//                   `=---='
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//         佛祖保佑       永无BUG

/**
 * Created by zcm on 2018/5/14.
 */
@Service
public class UserServicesImpl implements UserServices {

    @Autowired
    private UserDao userDao;
    @Autowired
    private RoleDao roleMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
//        UserDO user = userMapper.selectEnableByUsername(s);
//        if (user == null)
//            throw new UsernameNotFoundException("您登录的账号不存在或已被冻结");
//
//        //
//        List<Role> roles = roleMapper.selectByUserId(user.getUser_id());
//
//        //判断当前账号是否是商户号
//        boolean isMerchant = false;
//        for (Role role : roles) {
//            if ("ROLE_WAREHOUSE".equals(role.getRole_name())) {
//                isMerchant = true;
//                break;
//            }
//        }
//        if (!isMerchant)
//            throw new MessageException("您登录的账号不是发货员");
//
//        return new DefaultUserDetails(user, roles);
        return new DefaultUserDetails(null, null);
    }

    @Override
    public UserDO getUserDOByUserName(String userName) {
//        UserDO user = userDao.selectByUsername(userName);
//        return user;
        return null;
    }
}
